MAKE = make
CC = g++
AR = ar
CFLAGS = -g -ggdb -Iinc -Wall
SRCS := $(wildcard src/*.cpp)
OBJS := $(subst .cpp,.o, $(SRCS))
DEPS := $(subst .cpp,.d, $(SRCS))
TARGET = libutil.a

default: $(TARGET)

${TARGET}: ${OBJS}
	@$(AR) -r $(TARGET) $(OBJS)

%.o: %.cpp
	$(CC) $(CFLAGS) $< -c -o $@

-include $(DEPS)

%.d: %.cpp
	@set -e; rm -f $@; \
	$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

clean:
	-rm -rf $(OBJS) $(DEPS)

.PHONY: default clean